package com.example.yjh_login.activitys;


import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.lib_mvp.Constant;
import com.example.lib_mvp.arouter.path.ArouterPath;
import com.example.lib_mvp.base.mvp.BaseMvpActivity;
import com.example.lib_mvp.httpUtil.HttpUrl;
import com.example.yjh_login.R;
import com.example.yjh_login.presenterImp.LoginPresenter;
import com.tjf.lib_network.SpSaveUtils;
import com.tjf.lib_utils.LogsUtils;
import com.tjf.lib_utils.bean.BusEvent;

@Route(path = ArouterPath.PATH_LOGIN_AUTH_ORDER)
public class AuthOrderActivity extends BaseMvpActivity<LoginPresenter> implements View.OnClickListener {

    public View stateBar;
    public TextView lxkfTv;
    public ImageView backImg;
    public TextView textView6;
    public EditText orderActiveEdt;
    public LinearLayout hdOrderSaoyisaoLly;
    public FrameLayout orderActiveFly;
    public TextView orderActiveTv;

    @Override
    protected int getLayoutId() {
        return R.layout.hd_page_active_code;
    }

    @Override
    protected void initView() {
        super.initView();
        initViews();
    }

    @Override
    protected void initData() {
        hdOrderSaoyisaoLly.performClick();

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.back_img) {
            Bundle bundle = new Bundle();
            bundle.putInt("authOrder", 1);
            startActivity(LoginActivity.class, bundle);
            finish();
        } else if (id == R.id.hd_order_saoyisao_lly) {
            startScanPage(this);
        } else if (id == R.id.order_active_tv) {
            String orderId = orderActiveEdt.getText().toString();
            if (TextUtils.isEmpty(orderId)) {
                showToast("请先输入激活码");
                return;
            }
            getPresenter().getHdMyActivation(orderId);
        }
    }

    @Override
    public void onEventBus(BusEvent event) {
        super.onEventBus(event);
        if (1 == event.getActionStatus()) {
            LogsUtils.i("接口异常", event.getData());
            showToast(event.getData() + "");
            return;
        }
        if (Constant.OtherConstant.SAO_YI_SAO_RESULT.equals(event.getAction())) {
            orderActiveEdt.setText(event.getData() + "");
            return;
        }
        if (HttpUrl.MY_ACTIVATION.equals(event.getAction())) {
            showToast("设备已激活");
            SpSaveUtils.setActivation("1");
//            startActivity(MainActivity.class);
//            finish();
        }
    }

    LoginPresenter presenter;

    @Override
    public LoginPresenter getPresenter() {
        return presenter;
    }

    @Override
    public void intPresenter() {
        presenter = new LoginPresenter();
    }

    private void initViews() {
        stateBar = findViewById(R.id.state_bar);
        lxkfTv = findViewById(R.id.lxkf_tv);
        backImg = findViewById(R.id.back_img);
        textView6 = findViewById(R.id.textView6);
        orderActiveEdt = findViewById(R.id.order_active_edt);
        hdOrderSaoyisaoLly = findViewById(R.id.hd_order_saoyisao_lly);
        orderActiveFly = findViewById(R.id.order_active_fly);
        orderActiveTv = findViewById(R.id.order_active_tv);
        backImg.setOnClickListener(this);
        hdOrderSaoyisaoLly.setOnClickListener(this);
        orderActiveTv.setOnClickListener(this);
    }


}
